function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}
layui.define(["table", "form", "admin", "upload"], function (exports) {
    var $ = layui.$,
        table = layui.table,
        form = layui.form,
        upload = layui.upload,
        admin = layui.admin;

    // 监听单元格编辑:直接在单元格修改内容
    // 放在外部
    function revertCell(obj, field_name, old_base_hot) {
        var tableData = layui.table.cache['LAY-live-manage'];
        for (var i = 0; i < tableData.length; i++) {
            if (tableData[i].anchorid === obj.data.anchorid) {
                tableData[i][field_name] = old_base_hot;
                break;
            }
        }
        layui.table.reload('LAY-live-manage', {
            data: tableData
        });
    }

// 监听单元格编辑
    table.on('edit(LAY-live-manage)', function (obj) {
        var value = obj.value;
        var field_name = obj.field;
        var old_base_hot = obj.oldValue !== undefined ? obj.oldValue : obj.data[field_name];

        if (!/^\d+$/.test(value)) {
            revertCell(obj, field_name, old_base_hot);
            layer.msg('值只能为正整数', { icon: 5, time: 1000 });
            afterEdit(obj, field_name, old_base_hot);
            return;
        }

        var url = '/admin/live/heat_edit_post';
        if (field_name == 'hot') {
            url = '/admin/live/hot_edit_post';
        }

        layer.load();
        layui.admin.req({
            url: url,
            data: { id: obj.data.anchorid, heat: value, field_name: field_name },
            success: function (res) {
                layer.closeAll("loading");
                if (res.code == 0) {
                    parent.layer.msg(res.msg, { icon: 1, time: 1000 });
                } else {
                    revertCell(obj, field_name, old_base_hot);
                }
            },
            error: function () {
                revertCell(obj, field_name, old_base_hot);
                layer.msg('请求失败，请重试', { icon: 5, time: 1000 });
            },
            complete(res) {
                layer.closeAll("loading");
                afterEdit(obj, field_name, old_base_hot);
            }
        });
    });

// 事件后操作
    function afterEdit(obj, field_name, old_base_hot) {
        revertCell(obj, field_name, old_base_hot);
        console.log('edit事件已完成', obj);
    }

    //
    var adminid = Number(getCookie("uid"));

    table.render({
        elem: "#LAY-live-manage",
        url: "/admin/live/getlives",
        toolbar: '#toolbaar',
        editTrigger: 'dblclick',
        cols: [
            [
                { type: 'checkbox', fixed: 'left' },
                {
                    field: "",
                    title: "序号",
                    width: 60,
                    fixed: "left",
                    templet: function (d) {
                        return d.LAY_INDEX;
                    },
                },
                {
                    field: "",
                    width: 100,
                    title: "主播ID",
                    fixed: "left",
                    templet: function (d) {
                        return d.anchor ? d.anchor.id : '';
                    },
                },
                {
                    field: "",
                    title: "主播昵称",
                    fixed: "left",
                    width: 100,
                    templet: function (d) {
                        return d.anchor ? d.anchor.nick_name : '';
                    },
                },

                {
                    field: "",
                    title: "直播类型",
                    width: 100,
                    templet: function (d) {
                        return d.category ? d.category.title : '';
                    },
                },
                { field: "title", title: "直播标题", width: 200 },
                {
                    field: "",
                    title: "活动状态",
                    width: 100,
                    templet: function (d) {
                        return d.activity_toggle == 1 ? '<p><font color=red>开启中</font></p>' : '<p>未开启</p>';
                    }
                },
                {
                    field: "",
                    title: "高速推流",
                    width: 100,
                    templet: function (d) {
                        return d.enable_webrtc == 1 ? '<p><font color=red>开启中</font></p>' : '<p>未开启</p>';
                    }
                },
                {
                    field: "",
                    title: "直播封面",
                    width: 100,
                    templet: function (d) {
                        return (
                            '<img style="display: inline-block; width: auto; height: 100%;" layadmin-event="photosPreview" src="' +
                            d.thumb +
                            '"  value="' +
                            d.thumb +
                            '">'
                        );
                    },
                },
                {
                    field: "pull_flv_url",
                    title: "<font color=green>播流地址</font>",
                    width: 200,
                },
                {
                    field: "hot",
                    title: "当前热度",
                    width: 120,
                    sort: true,
                    edit: (typeof etype != 'undefined' && etype == 1) ? false : 'text',
                    templet: function (d) {
                        return (typeof etype != 'undefined' && etype == 1) ? d.hot : d.hot + '<i class="layui-icon layui-icon-edit"></i>';
                    },
                },
                {
                    field: "base_hot",
                    title: "基础热度",
                    width: 120,
                    sort: true,
                    edit: (typeof etype != 'undefined' && etype == 1) ? false : 'text',
                    templet: function (d) {
                        return (typeof etype != 'undefined' && etype == 1) ? d.base_hot : d.base_hot + '<i class="layui-icon layui-icon-edit"></i>';
                    },
                },
                {
                    field: "open_chat_num",
                    title: "<font color=green>点击私信人数</font>",
                    width: 130,
                    sort: true,
                },
                {
                    field: "send_chat_num",
                    title: "<font color=green>发起私信人数</font>",
                    width: 130,
                    sort: true,
                },
                {
                    field: "active_viewer",
                    title: "在线观众",
                    width: 100,
                    sort: true,
                },
                {
                    field: "high_count",
                    title: "观众峰值",
                    width: 100,
                    sort: true,
                },
                {
                    field: "unique_ip_count",
                    title: "累计IP",
                    width: 100,
                    sort: true,
                },
                {
                    field: "",
                    title: "标签",
                    width: 160,
                    templet: function (d) {
                        if (tags[d.tag]) {
                            return '<div style="background-color: ' + tags[d.tag].color + ';text-align: center">' + tags[d.tag].title + '</div>'
                        }

                        return '';
                    },
                },
                {
                    field: "",
                    title: "关联比赛ID",
                    width: 150,
                    templet: function (d) {
                        if (d.matchid) {
                            return d.matchid;
                        }
                        return "";
                    },
                },
                {
                    field: "",
                    title: "直播赛事",
                    width: 150,
                    templet: function (d) {
                        return d.matches ? d.matches.comp + '（' + d.matches.home + ' VS ' + d.matches.away + '）' : '';
                    },
                },

                {
                    field: "",
                    title: "关联房管ID",
                    width: 150,
                    templet: function (d) {
                        return d.anchorid;
                    },
                },

                { field: "start_stamp", title: "开播时间", width: 200 },
                {
                    field: "",
                    title: "直播状态",
                    width: 150,
                    templet: function (d) {
                        switch (d.status) {
                            case 0:
                                return "主播暂时离开";
                            case 1:
                                return "直播中";
                            case 2:
                                return "未开播";
                            default:
                                return "";
                        }
                    },
                },
                {
                    field: "",
                    title: "水印位置",
                    width: 150,
                    templet: function (d) {
                        switch (d.watermark_position) {
                            case 'l':
                                return "左";
                            case 'r':
                                return "右";
                            case 'n':
                                return "右";
                        }
                    },
                },
                {
                    field: "",
                    width: 100,
                    title: "开播来源",
                    templet: function (d) {
                        switch (d.platform) {
                            case 0:
                                return "web";
                            case 1:
                                return "安卓";
                            case 2:
                                return "IOS";
                            case 3:
                                return "后台直播";
                        }
                        return "";
                    },
                },
                {
                    title: "操作",
                    width: 350,
                    align: "center",
                    fixed: "right",
                    toolbar: "#table-livelist-live",
                },
            ],
        ],
        //主要利用回调渲染
        done: function (res, curr, count) {
            $('#statisIpTotal').text(res.ip_total);
            $('#statisViewerTotal').text(res.viewer_count);
        },
        page: true,
        limit: 20,
        height: "full-140",
        text: {
            none: '暂无数据'
        },
        even: true,
    });

    table.render({
        elem: "#LAY-live-duration",
        url: "/admin/live/ajax_user_duration?liveid=" + $('#liveid').val(),
        page: true,
        totalRow: true,
        editTrigger: 'dblclick',
        cols: [
            [
                {
                    field: "",
                    title: "用户ID",
                    width: 100,
                    fixed: "left",
                    templet: function (d) {
                        return d.uid;
                    },
                },
                {
                    field: "",
                    width: 150,
                    title: "帐号",
                    fixed: "left",
                    templet: function (d) {
                        return d.account ? d.account : '';
                    },
                },
                {
                    field: "",
                    title: "昵称",
                    width: 150,
                    templet: function (d) {
                        return d.nick_name ? d.nick_name : '';
                    },
                },

                {
                    field: "",
                    title: "登录设备",
                    width: 100,
                    templet: function (d) {
                        return d.login_platform ? d.login_platform : '';
                    },
                },
                {
                    field: "",
                    title: "在线时长[分钟]",
                    width: 200,
                    templet: function (d) {
                        return "<font color='red'>" + parseInt(d.duration / 60) + '分' + (d.duration % 60) + '秒' + "</font>    ";
                    },
                },
                {
                    field: "last_login",
                    title: "最近登录",
                    width: 200,
                },
                {
                    field: "regist_time",
                    title: "注册时间",
                    width: 200,
                }
            ],
        ],
        //主要利用回调渲染
        done: function (res, curr, count) {
            if (res.ip_total) {
                $('#statisIpTotal').text(res.ip_total);
            }
        },
        page: true,
        limit: 20,
        height: "full-140",
        text: {
            none: '暂无数据'
        },
        even: true,
    });

    table.render({
        elem: "#LAY-livelogs-manage",
        url: "/admin/live/getlogs",
        cols: [
            [
                { field: "id", width: 100, title: "ID", sort: true },
                {
                    field: "",
                    title: "主播",
                    width: 200,
                    templet: function (d) {
                        return d.anchor.nick_name + "(" + d.anchor.id + ")";
                    },
                },
                { field: "liveid", width: 200, title: "直播编号" },
                { field: "title", title: "标题", width: 200 },
                {
                    field: "",
                    title: "分类",
                    width: 150,
                    templet: function (d) {
                        return d.category.title;
                    },
                },
                { field: "start_time", title: "开播时间", width: 200 },
                { field: "end_time", width: 200, title: "结束时间" },
                {
                    field: "",
                    title: "直播时长",
                    width: 150,
                    templet: function (d) {
                        return formatSeconds(d.end_stamp - d.start_stamp);
                    },
                },
                { field: "gift_profit", minWidth: 100, title: "直播收益" },
            ],
        ],
        page: true,
        limit: 20,
        height: "full-140",
        text: "对不起，加载出现异常！",
        even: true,
    });

    table.render({
        elem: "#LAY-visit-history",
        url: "/admin/live/getlivestreamvisithistory",
        cols: [
            [
                { field: "id", width: 100, title: "ID", sort: true },
                { field: "user_name", width: 200, title: "使用者" },
                { field: "anchor_name", width: 200, title: "主播" },
                { field: "liveid", width: 200, title: "直播编号" },
                { field: "title", title: "标题", width: 200 },
                { field: "last_visit_time", minWidth: 100, title: "观看时间" },
            ],
        ],
        page: true,
        limit: 20,
        height: "full-140",
        text: "对不起，加载出现异常！",
        even: true,
    });

    table.render({
        elem: "#LAY-notice-manage",
        url: "/admin/live/notice_list",
        cols: [
            [
                { field: "id", title: "ID", sort: true, width: 70 },
                {
                    field: "content",
                    title: "公告内容",
                    width: 300
                },
                {
                    field: "link",
                    title: "发布人",
                    templet: function (d) {
                        if (d.admin != null) {
                            return d.admin.account;
                        }
                        return "";
                    },
                },
                { field: "create_time", title: "发布时间" },
                {
                    field: "",
                    title: "受众范围",
                    templet: function (d) {
                        switch (d.type) {
                            case 0:
                                return "全部房间";
                            case 1:
                                return '主播直播间：' + d.anchorid;
                            case 2:
                                return "娱乐房间";
                            case 3:
                                return "体育房间";
                        }
                        return "";
                    },
                },
                {
                    title: "操作",
                    width: 150,
                    align: "center",
                    fixed: "right",
                    toolbar: "#table-livenotice-operation",
                },
            ],
        ],
        page: true,
        limit: 20,
        height: "full-140",
        text: "对不起，加载出现异常！",
        even: true,
    });

    //查看照片
    admin.events.photosPreview = function (othis) {
        let urls = othis.attr("value");
        let urlarr = new Array();
        $.each(urls.split(","), function (i, val) {
            urlarr.push({ src: val });
        });
        layer.photos({
            photos: {
                title: "查看照片", //相册标题
                data: urlarr,
            },
            shade: 0.01,
            closeBtn: 1,
            anim: 5,
        });
    };

    table.on('toolbar(LAY-live-manage)', function (obj) {

        var data = table.checkStatus(obj.config.id);

        layer.confirm("确定要批量结束已勾选直播吗？", function (index) {
            if (obj.event == 'mult_end_live') {
                for (let index = 0; index < data.data.length; index++) {
                    layer.load();
                    admin.req({
                        url: "/admin/live/stop_post",
                        data: { liveid: data.data[index].liveid },
                        success(res) {
                            layer.closeAll();
                            if (res.code == 0) {
                                layer.msg(res.msg, { icon: 1 });
                                table.reload("LAY-live-manage");
                            } else {
                                layer.msg(res.msg, { icon: 5 });
                            }
                        },
                        complete(res) {
                            layer.closeAll("loading");
                        }

                    });
                }
            }

        });
    });

    //监听工具条
    table.on("tool(LAY-live-manage)", function (obj) {
        if (obj.event === "stop") {
            layer.confirm("确定要结束该直播吗？", function (index) {
                layer.load();
                admin.req({
                    url: "/admin/live/stop_post",
                    data: { liveid: obj.data.liveid },
                    success(res) {
                        layer.closeAll();
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 1 });
                            table.reload("LAY-live-manage");
                        } else {
                            layer.msg(res.msg, { icon: 5 });
                        }
                    },
                    complete(res) {
                        layer.closeAll("loading");
                    }

                });
            });
        } else if (obj.event === "link") {
            layer.prompt(
                {
                    formType: 0,
                    value: "",
                    title: "请输入比赛id",
                },
                function (value, index, elem) {
                    admin.req({
                        url: "/admin/live/linkmatch_post",
                        data: { id: obj.data.liveid, matchid: value },
                        success(res) {
                            if (res.code == 0) {
                                table.reload("LAY-live-manage");
                                layer.msg(res.msg, { icon: 1 });
                            } else {
                                layer.msg(res.msg, { icon: 5 });
                            }
                        },
                    });
                    layer.close(index);
                }
            );
        } else if (obj.event === "heatedit") {
            layer.open({
                type: 2,
                title: "直播间热度调整",
                content: "/admin/live/heat_edit?id=" + obj.data.anchorid,
                maxmin: true,
                area: ["650px", "350px"],
            });
        } else if (obj.event === "tag") {
            layer.open({
                type: 2,
                title: "标签管理",
                content: "/admin/live/tag?id=" + obj.data.anchorid,
                area: ["480px", "330px"],
            });
        } else if (obj.event === "edit") {
            layer.load();
            edit_anchor_id = obj.data.anchorid;
            $.ajax({
                type: "get",//请求方式
                url: '/admin/live/edit', //请求地址
                dataType: "html",//返回的数据类型
                data: { "id": edit_anchor_id },
                //请求成功 主要判断直播是否存在的问题
                success: function (res) {
                    layer.closeAll("loading");
                    if (isJSON(res)) {
                        var obj = JSON.parse(res);
                        if (obj.code == 1) {
                            layer.msg(obj.msg, { icon: 5, time: 2000 }, function () {
                                table.reload("LAY-live-manage");
                                $('body').find('.layui-layer-shade').click();
                            });
                        }
                    } else {
                        layer.open({
                            type: 2,
                            title: "修改直播",
                            content: '/admin/live/edit?id=' + edit_anchor_id,
                            area: ["700px", "500px"],
                        });
                    }
                },
                complete(res) {
                    layer.closeAll("loading");
                }
            });


        } else if (obj.event === "official") {
            admin.req({
                url: "/admin/live/official_type",
                data: { id: obj.data.anchorid, type: 1 },
                success(res) {
                    if (res.code == 0) {
                        table.reload("LAY-live-manage");
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        } else if (obj.event === "official_cancel") {
            admin.req({
                url: "/admin/live/official_type",
                data: { id: obj.data.anchorid, type: 0 },
                success(res) {
                    if (res.code == 0) {
                        table.reload("LAY-live-manage");
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        } else if (obj.event === "user_duration") {
            layer.open({
                type: 2,
                title: "用户在线时长",
                content: "/admin/live/user_duration?liveid=" + obj.data.liveid,
                maxmin: true,
                area: ["1500px", "750px"],
            });
        } else if (obj.event == 'activity_open') {
            admin.req({
                url: "/admin/live/activity_toggle",
                data: { id: obj.data.id, anchor_id: obj.data.anchorid, activity_toggle: 1 },
                success(res) {
                    if (res.code == 0) {
                        table.reload("LAY-live-manage");
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        } else if (obj.event == 'activity_close') {
            admin.req({
                url: "/admin/live/activity_toggle",
                data: { id: obj.data.id, anchor_id: obj.data.anchorid, activity_toggle: 0 },
                success(res) {
                    if (res.code == 0) {
                        table.reload("LAY-live-manage");
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        }
    });


    function isJSON(str) {
        try {
            var obj = JSON.parse(str);
            if (typeof obj == 'object' && obj) {
                return true;
            }
        } catch (e) {
            return false;
        }
        return false;
    }


    //上传图片
    var iconSrc = $("#LAY_iconImgSrc");
    upload.render({
        url: "/admin/index/noOperation",
        elem: "#LAY_iconImgUpload",
        auto: true,
        choose: function (obj) {
            layer.load();
            var choosefile;
            obj.preview(function (index, file, result) {
                choosefile = file;
            });
            admin.req({
                url: "/admin/live/signForCos",
                success: function (res) {
                    if (res.code == 0) {
                        var cos = new COS({
                            getAuthorization: function (options, callback) {
                                var credentials = res.data.credentials;
                                callback({
                                    TmpSecretId: credentials.tmpSecretId,
                                    TmpSecretKey: credentials.tmpSecretKey,
                                    XCosSecurityToken: credentials.sessionToken,
                                    ExpiredTime: res.data.expiredTime,
                                });
                            },
                            Domain: res.data.imgDomain,
                        });
                        cos.putObject(
                            {
                                Bucket: res.data.bucket,
                                Region: res.data.region,
                                Key: "images/" + res.data.filename + choosefile.name,
                                Body: choosefile,
                            },
                            function (err, data) {
                                layer.closeAll("loading");
                                if (err) {
                                    console.log("上传失败", err);
                                    layer.msg("上传失败", { icon: 5 });
                                } else {
                                    console.log("上传返回数据：", data)
                                    if (data.statusCode == 200) {
                                        iconSrc.val("https://" + data.Location);
                                    } else {
                                        layer.msg("图片上传失败", { icon: 5 });
                                    }
                                }
                            }
                        );
                    } else {
                        layer.closeAll("loading");
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        },
    });

    var iconSrc2 = $("#LAY_iconImgSrc2");
    upload.render({
        url: "/admin/index/noOperation",
        elem: "#LAY_iconImgUpload2",
        auto: true,
        choose: function (obj) {
            layer.load();
            var choosefile;
            obj.preview(function (index, file, result) {
                choosefile = file;
            });
            admin.req({
                url: "/admin/live/signForCos",
                success: function (res) {
                    if (res.code == 0) {
                        var cos = new COS({
                            getAuthorization: function (options, callback) {
                                var credentials = res.data.credentials;
                                callback({
                                    TmpSecretId: credentials.tmpSecretId,
                                    TmpSecretKey: credentials.tmpSecretKey,
                                    XCosSecurityToken: credentials.sessionToken,
                                    ExpiredTime: res.data.expiredTime,
                                });
                            },
                            Domain: res.data.imgDomain,
                        });
                        cos.putObject(
                            {
                                Bucket: res.data.bucket,
                                Region: res.data.region,
                                Key: "images/" + res.data.filename + choosefile.name,
                                Body: choosefile,
                                StorageClass: 'STANDARD',
                            },
                            function (err, data) {
                                layer.closeAll("loading");
                                if (err) {
                                    console.log("上传失败", err);
                                    layer.msg("上传失败", { icon: 5 });
                                } else {
                                    console.log("上传数据", data)
                                    if (data.statusCode == 200) {
                                        iconSrc2.val("https://" + data.Location);
                                    } else {
                                        layer.msg("图片上传失败", { icon: 5 });
                                    }
                                }
                            }
                        );
                    } else {
                        layer.closeAll("loading");
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
            });
        },
    });

    //查看图标
    admin.events.coverImgPreview = function (othis) {
        var src = iconSrc.val();
        layer.photos({
            photos: {
                title: "查看图标", //相册标题
                data: [
                    {
                        src: src, //原图地址
                    },
                ],
            },
            shade: 0.01,
            closeBtn: 1,
            anim: 5,
        });
    };

    //查看视频
    admin.events.upVideoPreview = function (othis) {
        let video_url = $('#LAY_videoSrc').val();
        if (!video_url) {
            return layer.msg("请填写播流地址", { icon: 5 });
        }
        var html = ` 
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div id="id_player" style='width: 800px; height: 400px;'></div>
                </div>
            </div>
                <script>
                var player = new TcPlayer('id_player', {
                    "m3u8": '${video_url}', //请替换成实际可用的播放地址
                    "autoplay" : true,      //iOS 下 safari 浏览器，以及大部分移动端浏览器是不开放视频自动播放这个能力的
                    "poster" : "",
                    'live' : 'true'
                });
                </script>`

        layer.open({
            type: 1,
            title: "视频预览",
            content: html,
            area: ["800px", "450px"],
        });
    };

    function getVodSignature() {
        return axios.post("/admin/live/signForVod").then(function (response) {
            return response.data.data.sign;
        });
    }


    // ip统计
    table.render({
        elem: '#LAY-source-everyday-manage'
        , url: '/admin/live/get_totalip_list'
        , cols: [[
            { field: 'date_str', title: '日期' }
            , { field: 'ip_count', title: 'IP个数(总站)' }
            , { field: 'device_count', title: '设备总数(直播间)' }
            , { field: 'android_count', title: '安卓APP设备数(直播间)' }
            , { field: 'ios_count', title: '苹果APP设备数(直播间)' }
            , { field: 'pc_count', title: '访问PC设备数(直播间)' }
            , { field: 'h5_count', title: '访问H5设备数(直播间)' }
        ]]
        , page: true
        , limit: 20
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });


    exports("live", {});
});

function formatSeconds(value) {
    var secondTime = parseInt(value); // 秒
    var minuteTime = 0; // 分
    var hourTime = 0; // 小时
    if (secondTime > 60) {
        //如果秒数大于60，将秒数转换成整数
        //获取分钟，除以60取整数，得到整数分钟
        minuteTime = parseInt(secondTime / 60);
        //获取秒数，秒数取佘，得到整数秒数
        secondTime = parseInt(secondTime % 60);
        //如果分钟大于60，将分钟转换成小时
        if (minuteTime > 60) {
            //获取小时，获取分钟除以60，得到整数小时
            hourTime = parseInt(minuteTime / 60);
            //获取小时后取佘的分，获取分钟除以60取佘的分
            minuteTime = parseInt(minuteTime % 60);
        }
    }
    var result =
        "" + parseInt(secondTime) >= 10
            ? parseInt(secondTime)
            : "0" + parseInt(secondTime);

    if (minuteTime > 0) {
        result =
            "" +
            (parseInt(minuteTime) >= 10
                ? parseInt(minuteTime)
                : "0" + parseInt(minuteTime)) +
            ":" +
            result;
    } else {
        result = "" + "00:" + result;
    }

    if (hourTime > 0) {
        result =
            "" +
            (parseInt(hourTime) >= 10
                ? parseInt(hourTime)
                : "0" + parseInt(hourTime)) +
            ":" +
            result;
    } else {
        result = "" + "00:" + result;
    }

    return result;
}
